package jeni2.VCD;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.Toast;

public class inputvcd extends Activity {
    /** Called when the activity is first created. */
	private EditText tkode,tjudul,thargasewa;
	private Spinner tkategori;
	private Button add, back;
	private buatdatabase dbadap;
	String[] kateg = {"Film","MP3","Software"};
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        dbadap = new buatdatabase(this);
        dbadap.open();
        setContentView(R.layout.forminputvcd);        
        add = (Button) findViewById(R.id.add);
        back = (Button) findViewById(R.id.back);
        tjudul = (EditText) findViewById(R.id.judul);
        tkategori = (Spinner) findViewById(R.id.kategory);
        thargasewa = (EditText) findViewById(R.id.hargasewa);
        ArrayAdapter <String> adapter = new ArrayAdapter <String> (this,android.R.layout.simple_spinner_item,kateg);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        tkategori.setAdapter(adapter);
        add.setOnClickListener(new OnClickListener() {
			
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				String judul = tjudul.getText().toString();
				String kategori = (String) tkategori.getSelectedItem();
				String hargasewa = thargasewa.getText().toString();
				if(judul.equals("") || kategori.equals("") || hargasewa.equals("")){
					Toast.makeText(getBaseContext(), "Masih ada yang kosong", Toast.LENGTH_SHORT).show();
				}else{
				try
				{
					dbadap.createAddress(judul, kategori, hargasewa);
					Toast.makeText(getBaseContext(), "Data have been successfully added", Toast.LENGTH_SHORT).show();
				}
				catch(Exception e)
				{
					Toast.makeText(getBaseContext(), e.toString(), Toast.LENGTH_SHORT).show();
				}
				setResult(RESULT_OK);
				finish();
			}}
		});
       back.setOnClickListener(new OnClickListener() {
			
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				Intent intent = new Intent(inputvcd.this, menuvcd.class);
				startActivity(intent);
			}
		});
    }
}